--used globlas 

SCREEN_WIDTH = 250
SCREEN_HEIGHT = 192
dofile('globalfunc.lua')

Gameelement = {
	name = 'a gameelement',
---------------------------------Informations for displaying and calculating colision
	x = 0, 
	y = 0,
	wid = 0, -- for collision area
	hig = 0,
	x_offset = 0, -- offset for collision area
	y_offset = 0,
	z_index = 1, -- on which layer it will be painted
	passable = true,
	dir = directions[math.random(1,8)], -- Himmelsrichtung
	currentState = {},
	image = {
  		default = 'resources/default.png'

  	},	
---------------Element informatio
	oht = {},
}

GameElementCollection = {} -- collects all existing gameelements

function Gameelement:new(o) --TODO: check if deep clone theory would be usefull
  o = o or {} -- if no table is set , create an empty table
  setmetatable(o, self)
  self.__index = self
  o.dir = directions[math.random(1,8)]
  o.x = math.random(0, SCREEN_WIDTH - self.wid)	
  o.y = math.random( 0, SCREEN_HEIGHT - self.hig)
  table.insert(GameElementCollection,o)                    --JAN: I changed self to o. I guess self was wrong
  return o 
end



function Gameelement:dealDamage(target, amount)
	target:getDamage(amount,self
	)
end

function Gameelement:move(x,y)
	self.x = self.x - x
	self.y = self.y -y
	
end

function Gameelement:destroy(destroyer) --if monster dies, this functions delet the monster and gives  exp to the hero
    destroyer.exp = destroyer.exp + self.exp
	self = nil -- set table to nil
	-- TODO: collect the garbage?
	-- collectgarbage()
	-- print(self)
	-- return self
end

function Gameelement:runState()
	for i,v in	pairs (self.currentState) do 
		v(self)
	end
end

-- -- -- -- -- -- -- -
-- -- OVERHEAD TEXT --
-- -- -- -- -- -- -- -
--ToDo: enable multible OHT's

Gameelement.oht = {}

--Ein neuer OHT wird erstellt
function 	Gameelement:newoht(text)
	self.oht.status = 1
	self.oht.text = text
	self.oht.starttime = clock.second
end
	
--der OHT wird angezeigt
function Gameelement:runoht()
	if  clock.second - self.oht.starttime < 3 then 
	else
		self.oht.status = 0
	end
end

dofile('States.lua')

dofile('permanentGameelement.lua')
dofile('temporaryGameelement.lua')

